<?php
/**
 * 新闻资讯模块
 **/
namespace Mama\Controller;
use Think\Controller;

class RecruitController extends Controller {
	public function __construct() {
        parent::__construct();
		//判断是否登陆
		if(!session('userid')){ //已登陆
			$this->redirect("index/index");
		}

		$this->assign('shoplist', S('shoplist_'. session('userid')));
    }
	
	/**
	 * 获取招聘列表
	 **/
	public function index(){
		$ajax = I('get.ajax', 0);
    	$page = I('get.page', 1);
    	//条件
    	$visible = I('get.visible');
		if($visible != 'all' && !isset($visible)){
			$where['visible'] = $visible;
		}
		
    	$recruitDao = D('Recruit');
    	//总数
    	$count = $recruitDao->getRecruitCount($where);
    	$this->assign('count', $count);
    	//列表
    	$recruitlist = $recruitDao->getRecruitList($page, $where);
    	$this->assign('recruitlist', $recruitlist);
    	if($ajax){
    		$this->display('recruit_list', 'utf-8', 'html');
    	}else{
    		$this->display();
    	}
	}
	
	/**
	 * 发布招聘
	 **/
	public function add(){
		if(IS_GET){
			$id = I('get.id', 0);
			$info = D('Recruit')->getRecruitInfo($id);
			$this->assign('info', $info);
			$this->display();
		}else{
			$data = I('post.');
			$data['admin_id'] = session('userid');
			$data['admin_nick'] = session('nickname');
			$data['createtime'] = time();
			//判断是否编辑OR添加
			if($data['id']){
				$id = $data['id'];
				$row = D('Recruit')->editResruitInfo($id, $data);
			}else{
				$row = D('Recruit')->addRecruitInfo($data);
			}
			
			if($row !== false){
				echo 1;
			}else{
				echo 0;
			}
		}
	}
}
